global class scheduledCxG_CampaignMemberControlGroup implements Schedulable{

  ID CxGcampaignrecordtypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Campaign', 'CXG_Campaign');        
  
  global void execute(SchedulableContext sc) {
     
  list<Campaign> campList = new list<Campaign>();
  list<CXG_Campaign_Accounts__c> campmemlist = new list<CXG_Campaign_Accounts__c>();     
  CxG_CampaignMemberControlGroup campaignMemberUpdate = new CxG_CampaignMemberControlGroup();
      
  list<Campaign> clist  = [Select id,Number_of_Control_Group_Members__c,Days_since_Start__c from Campaign where IsActive = True and StartDate != null and recordtypeid =:CxGcampaignrecordtypeID and Days_since_Start__c>0 ];
  campmemlist = [Select id, Control_Group_Member__c, Ownerid from CXG_Campaign_Accounts__c where Days_Remaining__c=60];
    for(Campaign  c :cList){
         Integer N = Integer.valueOf(c.Days_since_Start__c);
         Decimal remainder = math.mod(N, 30);
         if(remainder == 0){
             campList.add(c);
         }
       }
       
     // if(camplist.size()>0){
     // update campList;
     // }
      campaignMemberUpdate.AssignControlGroupMember(campList);
      campaignMemberUpdate.RemoveControlGroupMember(campmemlist);
    }
   
   /* test class for classes/triggers */  
   
    static testMethod void testscheduledCxG_CampaignMemberControlGroup() {
      test.starttest();       
       scheduledCxG_CampaignMemberControlGroup  sat = new scheduledCxG_CampaignMemberControlGroup();
       String at = '0 0 23 * * ?';        
       system.schedule('Scheduled Control group', at, sat);
       test.stopTest();
       }  
}